<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        #coutent{
            width: 300px;
            height: 300px;
            margin: 0 auto;
        }
        #info p{
            height: 30px;
            border-bottom:1px solid #ccc;
            margin-top: 10px; 
            background: yellowgreen;
            border-radius: 15px;
            color: #fff;
            line-height: 30px;
            padding-left: 10px;
        }
        h2{
            text-align: center;
        }
        #th{
            text-align: center;
        }
        #stu{
            width: 150px;
            height: 30px;
            background: lightblue;
            color:#fff;
            border-radius:20px; 
        }
    </style>
</head>
<body>
    <div id="coutent">
        <h2>学生信息表</h2>
        <p id="th">
            <select name="" id="stu">
                <option value="">请选择</option>
                <option value="stu1">第一位学生</option>
                <option value="stu2">第二位学生</option>
                <option value="stu3">第三位学生</option>
            </select>
        </p>
        <div id="info">
            <p id="username"></p>
            <p id="age"></p>
            <p id="heigth"></p>
            <p id="sex"></p>
            <p id="hobby"></p>
            <p id="study"></p>
        </div>
        
    </div>
   
    <script>
        var stu=document.getElementById('stu');
        stu.addEventListener('change',function(){
            if(this.value==''){
                return;
            }
            var xhr = new XMLHttpRequest();
            xhr.open('get','/student?id='+this.value, true);
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    var responseText=JSON.parse(xhr.responseText);
                    document.getElementById('username').innerHTML ='姓名：'+responseText.username;
                    document.getElementById('age').innerHTML ='年龄：'+responseText.age;
                    document.getElementById('heigth').innerHTML ='身高：'+responseText.heigth;
                    document.getElementById('sex').innerHTML ='性别：'+responseText.sex;
                    document.getElementById('hobby').innerHTML ='爱好：'+responseText.hobby;
                    document.getElementById('study').innerHTML ='学习：'+responseText.study;
                }else{
                    document.getElementById('username').innerHTML = '获取数据失败'
                }
            }
            xhr.send();
        });
    </script>
</body>
</html>